package com.cn.yugan.Engine.Adapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cn.yugan.Engine.Holder.ArticleItemHolder;
import com.cn.yugan.mobile.R;

import java.util.List;
import java.util.Map;

/**
 * Created by Rover on 2016/7/22 .
 * Email 357319517@qq.com
 */
public class HistoryListViewAdpater extends BaseAdapter {
    private Context context;
    private List<Map<String, Object>> mlist;
    private LayoutInflater layoutInflater;
    private ArticleItemHolder articleItemHolder;
    private int status;

    public HistoryListViewAdpater(Context context, List<Map<String, Object>> mlist, int status) {
        this.context = context;
        this.mlist = mlist;
        this.layoutInflater = LayoutInflater.from(context);
        this.status = status;
    }

    public void setstatus(int status) {
        this.status = status;
    }

    
    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        articleItemHolder = null;

        if (convertView == null) {
            articleItemHolder = new ArticleItemHolder();
            convertView = layoutInflater.inflate(R.layout.list_item_normal, null);
            articleItemHolder.author = (TextView) convertView.findViewById(R.id.list_item_author);
            articleItemHolder.commit = (TextView) convertView.findViewById(R.id.list_item_commit);
            articleItemHolder.title = (TextView) convertView.findViewById(R.id.list_item_title);
           // articleItemHolder.active = (TextView) convertView.findViewById(R.id.list_item_active);
            articleItemHolder.see = (TextView) convertView.findViewById(R.id.list_item_see);
            convertView.setTag(articleItemHolder);
        } else {
            articleItemHolder = (ArticleItemHolder) convertView.getTag();
        }
//        if (status == HistoryActivity.MENU_DELECT) {
//            articleItemHolder.Isdelect = (LinearLayout) convertView.findViewById(R.id.list_item_ll_checked);
//            CheckBox checkBox = new CheckBox(context);
//            articleItemHolder.Isdelect.addView(checkBox);
//        } else if (status == HistoryActivity.MENU_NORMAL) {
//            articleItemHolder.Isdelect = (LinearLayout) convertView.findViewById(R.id.list_item_ll_checked);
//            articleItemHolder.Isdelect.setVisibility(View.INVISIBLE);
//        }
        String title = (String) mlist.get(position).get("title");
        articleItemHolder.title.setText(Html.fromHtml(title));
        articleItemHolder.commit.setText(String.valueOf(mlist.get(position).get("commit")));
        articleItemHolder.author.setText("Up猪:" + (String) mlist.get(position).get("author"));
        articleItemHolder.see.setText("围观:" + String.valueOf(mlist.get(position).get("see")));
//        switch (String.valueOf(mlist.get(position).get("channelId"))) {
//
//            case "110":
//                articleItemHolder.active.setText("综合");
//                break;
//            case "73":
//                articleItemHolder.active.setText("工作乀情感");
//                break;
//            case "74":
//                articleItemHolder.active.setText("动漫文化");
//                break;
//            case "75":
//                articleItemHolder.active.setText("漫画乀轻小说");
//                break;
//            case "164":
//                articleItemHolder.active.setText("游戏");
//                break;
//            default:
//                articleItemHolder.active.setText("文章");
//                break;
//        }
        return convertView;
    }
}
